#ifndef REGISTER_SURPPORT_H
#define REGISTER_SURPPORT_H

#include <boost/shared_ptr.hpp>
#include <map>
using namespace std;

template<typename IndexType, typename RegisteeType>
class IRegister
{
public:
	typedef boost::shared_ptr< RegisteeType > RegisteePtr;
protected:
	typedef map<IndexType, RegisteePtr> Map;
	typedef typename Map::iterator Itr;
	Map map_;
public:
	virtual void add(const IndexType& index, RegisteePtr registee)
	{
		map_[index] = registee;
	}

	virtual RegisteePtr get(const IndexType& index)
	{
		Itr itr = map_.find(index);
		if(itr == map_.end()) { return RegisteePtr();}
		return RegisteePtr((*itr).second);
	}

	virtual void remove(const IndexType& index)
	{
		map_.erase(index);
	}

	virtual ~IRegister(){};
};

#endif